package com.leetcode.LC;

public class LC888 {
    public int[] fairCandySwap(int[] A, int[] B) {

        int sumA=0,sumB=0,dis=0;
        for (int i : A) {
            sumA+=i;
        }
        for (int i : B) {
            sumB+=i;
        }
        dis=Math.abs(sumA-sumB)/2;
        int[] ints = new int[2];
        if (sumA>sumB){
            for (int i = 0; i < A.length; i++) {
                for (int j = 0; j < B.length; j++) {
                    if (A[i]-B[j]==dis){
                        return new int[]{A[i],B[j]};
                    }
                }
            }
        }else {
            for (int i = 0; i < A.length; i++) {
                for (int j = 0; j < B.length; j++) {
                    if (B[j]-A[i]==dis){
                        return new int[]{A[i],B[j]};
                    }
                }
            }
        }
        return new int[]{};
        
    }

    public static void main(String[] args) {
        for (int i : new LC888().fairCandySwap(new int[]{2}, new int[]{1,3})) {
            System.out.print(i+" ");
        }
    }
}
